import request from '@/utils/request'
import type { 
  LoginData, 
  RegisterData, 
  ApiResponse, 
  LoginResponse, 
  User,
  ForgotPasswordResponse 
} from '@/types/auth'

export const authApi = {
  // 用户注册
  register(data: RegisterData): Promise<ApiResponse<User>> {
    return request.post('/auth/register', data)
  },

  // 用户登录
  login(data: LoginData): Promise<ApiResponse<LoginResponse>> {
    return request.post('/auth/login', data)
  },

  // 退出登录
  logout(): Promise<ApiResponse> {
    return request.post('/auth/logout')
  },

  // 获取当前用户信息
  getCurrentUser(): Promise<ApiResponse<User>> {
    return request.get('/users/profile')
  },

  // 忘记密码
  forgotPassword(email: string): Promise<ApiResponse<ForgotPasswordResponse>> {
    return request.post('/auth/forgot-password', { email })
  },

  // 重置密码
  resetPassword(token: string, password: string): Promise<ApiResponse> {
    return request.post('/auth/reset-password', { token, password })
  },

  // 修改密码
  changePassword(currentPassword: string, newPassword: string): Promise<ApiResponse> {
    return request.post('/users/change-password', { currentPassword, newPassword })
  }
}